#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

int main() {
    int fd = open("test.txt", O_RDWR | O_CREAT, 0666);
    if (fd == -1) {
        perror("open failed");
        exit(1);
    }
    int flags = fcntl(fd, F_GETFL);
    printf("Original flags: %d\n", flags);
    if (fcntl(fd, F_SETFL, flags | O_APPEND) == -1) {
        perror("fcntl F_SETFL failed");
        exit(1);
    }
    if (write(fd, "Appended data\n", 14) == -1) {
        perror("write failed");
        exit(1);
    }
    close(fd);
    return 0;
}
